package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysComplaint;
import com.gec.model.entity.SysRepair;
import com.gec.model.vo.SysComplaintVo;
import com.gec.model.vo.SysRepairVo;
import com.gec.system.service.SysCommunityService;
import com.gec.system.service.SysComplaintService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 投诉表 前端控制器
 * </p>
 *
 * @author lmd
 * @since 2023-12-08
 */
@Api(tags = "投诉管理控制器")
@RestController
@RequestMapping("/admin/system/sysComplaint")
public class SysComplaintController {

    @Autowired
    private SysComplaintService sysComplaintService;


    @ApiOperation("查询所有投诉信息")
    @GetMapping("/findAllComplaint")
    public Result findAllComplaint(){

        List<SysComplaint> list = this.sysComplaintService.list();
        return Result.ok(list);
    }

    @ApiOperation("分类查询")
    @GetMapping("/{page}/{limit}")
    public Result selectComplaintPageVo(@PathVariable Long page,
                                     @PathVariable Long limit,
                                     SysComplaintVo sysComplaintVo
    ){
        IPage<SysComplaint> iPage =new Page<>(page,limit);

        System.out.println("iPage条件："+iPage);

        iPage=this.sysComplaintService.selectPage(iPage,sysComplaintVo);

        System.out.println("控制层打印投诉信息："+iPage);
        return Result.ok(iPage);
    }

    //    新增
    @ApiOperation("新增投诉信息")
    @PostMapping("/addComplaint")
    public Result addComplaint(@RequestBody SysComplaint sysComplaint) {
        boolean save = this.sysComplaintService.save(sysComplaint);
        return save ? Result.ok() : Result.fail();

    }

    // 修改
    //1.根据id 去得到当前分类
    @ApiOperation("根据id获取投诉信息")
    @GetMapping("/findComplaintById/{id}")
    public Result findComplaintById(@PathVariable Long id)
    {
        SysComplaint sysComplaint = this.sysComplaintService.getById(id);
        return Result.ok(sysComplaint);
    }

    // 实现修改
    @ApiOperation("修改投诉信息")
    @PostMapping("/updateComplaint")
    public Result updateComplaint(@RequestBody SysComplaint sysComplaint)
    {
        boolean b = this.sysComplaintService.updateById(sysComplaint);
        return b ? Result.ok() : Result.fail();

    }

    //    根据单个id 删除数据
    @ApiOperation("根据id删除投诉信息")
    @DeleteMapping("/removeComplaintById/{id}")
    public Result removeComplaintById(@PathVariable Long id){

        boolean b = this.sysComplaintService.removeById(id);
        return b ? Result.ok() : Result.fail();

    }

    // 批量删除
    @ApiOperation("批量删除投诉信息")
    @DeleteMapping("/removeComplaintByIds")
    public Result removeComplaintByIds(@RequestBody List<Long> ids)
    {
        boolean b = this.sysComplaintService.removeByIds(ids);

        return b ? Result.ok() : Result.fail();

    }


    // 更改投诉状态
    @ApiOperation("更改投诉状态")
    @GetMapping("/updateComplaintStatus/{id}/{status}")
    public Result updateComplaintStatus(@PathVariable Long id,
                                     @PathVariable Integer status)
    {
        this.sysComplaintService.updateRepairStatus(id,status);

        return Result.ok();
    }
}

